package com.cn.action;

import com.cn.entity.NewsEntity;
import com.cn.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

public class AddNewsAction implements ActionInterface {
    NewsService ns = new NewsService();

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {
        //得到新闻标题文本框的值
        String title = request.getParameter("newstitle");
        //得到新闻正文文本框的值
        StringBuffer newscontent = new StringBuffer(request.getParameter("newscontent"));
        //创建一个新闻对象
        NewsEntity newsEntity = new NewsEntity();
        //设置对象的新闻标题值
        newsEntity.setTitle(title);
        //设置对象的新闻正文值
        newsEntity.setContent(newscontent.toString());
        //传到service 里面进行操作
        ns.addNews(newsEntity);
        return "ht_news_add.jsp";
    }
}
